const Mock = require('mockjs')
let data=[
    {   
        "id":1,
        "name":"宋该核",
        "phone":"18790896556",
        "password":"020328"
    },
    {   
        "id":2,
        "name":"刘学永",
        "phone":"15232630979",
        "password":"123456"
    },
    {   
        "id":3,
        "name":"马强",
        "phone":"15236130210",
        "password":"654321"
    },
    {   
        "id":4,
        "name":"葛菲",
        "phone":"18366296936",
        "password":"000000"
    }
    ,
    {   
        "id":5,
        "name":"郭喜",
        "phone":"15516591620",
        "password":"1234567"
    }
]
Mock.mock('/api/login', 'post', function (option) {
    let opt = JSON.parse(option.body);
    //判断 前端传过来的值和接口中定义的数据是否一直
    let msg;
    data.forEach( (item,index) => {
        if(item.phone == opt.phone && item.password == opt.password){
            msg = item;
        }
        
    })
    if(msg){
        return {
            code: 200,
            data: msg,
            message: 'success'
        }
    }else{
        return {
            code: 500,
            data: "请求失败",
            message: 'error'
        }
    }
    
})